package com.example.dao;

import com.example.model.pojo.Reply;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author 27954
 * @Description TODO
 * @Date 2022/9/22 8:38
 */
@Transactional
public interface ReplyDao extends JpaRepository<Reply,Integer> {
    @Query(value = "select * from reply where c_id=?1 and status=1",nativeQuery = true)
    List<Reply> findAllByCIdaAndToUid(Integer cid);
    @Query(value = "select * from reply where to_uid=?1 and status=1" ,nativeQuery = true)
    Reply getByToRid(Integer rid);
    @Query(value = "select count(*) from reply group by rid=? and status=1" ,nativeQuery = true)
    Integer getCount(Integer rid);
    int countByToUid(Integer rid);
    @Modifying
    @Query(value = "update reply set status=0 where rid=?1 and uid=?2 and status=1",nativeQuery = true)
    void deleteByRidAndUid(Integer rid,Integer uid);
}
